using System;
using Science.Mathematics;
using L=Science.Physics.GeneralPhysics;
using M = Science.Mathematics.Calculus;

namespace Serway.Chapter06
{
	/// <summary>
	/// Example15: Euler and the Sphere in Oil Revisited
	/// Consider the sphere falling in oil in Example 6.10. 
	/// Using the Euler method, find the position and the 
	/// acceleration of the sphere at the instant that speed 
	/// reachers 90.0% of terminal speed.
	/// y = -0.035 cm
	/// a = -99 cm/s^2
	/// </summary>
	public class Example15
	{
		public Example15()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}

		private double tau = 0.0051;
		private double t = 0.0117;
		private double v_t = -0.05;
		public void Compute()
		{
			// dv/dt = - g + g/v_t*v
			// at v = 0.9*v_t, dv/dt = - g + g*0.9
			double g = L.Constant.AccelerationOfGravity;
			result += Convert.ToString(-g+g*0.9)+"    ";
		
			Function.DoubleToDouble v 
				= new Function.DoubleToDouble(VvsT);
			M.Integration1D obj = new M.Integration1D(v);
			obj.From = 0.0;
			obj.To = t;
			obj.Compute();
			result += Convert.ToString(obj.Result);
		}
		private double VvsT(double t)
		{
			return v_t*(1.0-Math.Exp(-t/tau));
		}
	}
}
